//
//  RoseCell.m
//  ROSE
//
//  Created by 艾阳 on 2018/5/31.
//  Copyright © 2018年 HeNanZhongDunYunAn. All rights reserved.
//

#import "RoseCell.h"

@implementation RoseCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) { 
        self.backgroundColor = [UIColor whiteColor];
        if (!_imgView) {
            _imgView = [[UIImageView alloc]init];
            _imgView.contentMode = UIViewContentModeScaleAspectFit;
            _imgView.backgroundColor = ZS_UIColorMakeWithRGBA(255, 228, 225, 1);
            //UIViewContentModeScaleAspectFill;
            [self.contentView addSubview:_imgView];
        }
        if(!_status){
            _status = [[UILabel alloc]init];
            _status.layer.cornerRadius = 5.0f;
            _status.layer.masksToBounds = YES;
            _status.backgroundColor = [UIColor colorWithRed:233/255.0 green:206/255.0
                                                       blue:133/255.0 alpha:1];
            _status.textColor = [UIColor whiteColor];
            _status.textAlignment = NSTextAlignmentCenter;
            _status.font = [UIFont systemFontOfSize:10];
            _status.text = @"创世";
            [self.contentView addSubview:_status];
        }
        if(!_days){
            _days = [[UILabel alloc]init];
            _days.layer.masksToBounds = YES;
            _days.layer.cornerRadius = 5.0f;
            _days.backgroundColor = [UIColor colorWithRed:233/255.0 green:123/255.0
                                                       blue:155/255.0 alpha:1];
            _days.textColor = [UIColor whiteColor];
            _days.textAlignment = NSTextAlignmentCenter;
            _days.font = [UIFont systemFontOfSize:10];
            _days.text = @"6531天";
            [self.contentView addSubview:_days];
        }
        if (!_name) {
            _name = [[UILabel alloc]init];
            _name.textColor = [UIColor blackColor];
            _name.font = [UIFont systemFontOfSize:15];
            _name.backgroundColor = [UIColor clearColor];
            _name.text = @"粉红回忆";
            [self.contentView addSubview:_name];
        }
        if (!_price) {
            _price = [[UILabel alloc]init];
            _price.textColor =  [UIColor colorWithRed:233/255.0 green:123/255.0
                                                 blue:155/255.0 alpha:1];
            _price.text = @"50.00ETH";
            _price.font = [UIFont systemFontOfSize:13];
            [self.contentView addSubview:_price];
        }
        [self makeLayout];
    }
    return self;
}


- (void)makeLayout{

    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 80, 0));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo((size_width-85)/2*384.0/518.0);
        }];
        
    [self.status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.imgView.mas_bottom).with.offset(6.0f);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(16);
    }];
    
    [self.days mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.status.mas_right).with.offset(5);
        make.top.mas_equalTo(self.imgView.mas_bottom).with.offset(6.0f);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(16);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.status.mas_bottom).with.offset(6.0f);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(16);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.name.mas_bottom).with.offset(6.0f);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(16);
    }];
    
}

- (void)setDataWithRoseModel:(RoseModel *)roseModel{
    [self.imgView setImage:[self stringToImage:roseModel.BASE64]];
    self.status.text = roseModel.DJMC;
    self.name.text = roseModel.MC;
    self.days.text = [NSString stringWithFormat:@"%@天",roseModel.AGE];
    self.price.text = [NSString stringWithFormat:@"%@ROST",roseModel.SJJG];
}
// 64base字符串转图片

- (UIImage *)stringToImage:(NSString *)str {
    
    NSData * imageData =[[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    UIImage *photo = [UIImage imageWithData:imageData ];
    
    return photo;
    
}


@end
